<script setup>
import { ref, onMounted, getCurrentInstance } from 'vue'
import * as echarts from 'echarts'
import { pieData } from '@/socket'

const props = defineProps({
  radius: {
    type: [String, Array],
    default: '50%'
  }
})
const main = ref(null)
const { proxy } = getCurrentInstance()
const initChart = (myChart) => {
  // 绘制图表
  myChart.setOption({
    series: [
      {
        name: 'Access From',
        type: 'pie',
        radius: props.radius,
        data: pieData,
        emphasis: {
          itemStyle: {
            shadowBlur: 10,
            shadowOffsetX: 0,
            shadowColor: 'rgba(0, 0, 0, 0.5)'
          }
        }
      }
    ]
  })
}
onMounted(() => {
  // 基于准备好的dom，初始化echarts实例
  const myChart = echarts.init(proxy.$refs.main)
  setInterval(() => initChart(myChart), 1000)
})
</script>

<template>
  <div id="main" ref="main"></div>
</template>

<style lang="scss" scoped>
#main {
  width: 100%;
  height: 100%;
}
</style>
